package com.kede.app.rest;

import com.kede.annotation.AnonymousAccess;
import com.kede.app.domain.Users;
import com.kede.app.ienum.AppIdTypeEnum;
import com.kede.app.repository.UsersRepository;
import com.kede.app.service.UsersService;
import com.kede.pojo.ResHttp;
import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/5/22 17:09
 ***/
@RequestMapping("util")
@RestController
public class UtilController {

    @Resource
    private UsersRepository usersRepository;


    /**
     * 获取各端注册数
     **/
    @AnonymousAccess
    @GetMapping("getRegisterNum")
    public ResHttp getRegister(){
        Users users = new Users();
        users.setStatus("1");
        //用户
        users.setUserType(AppIdTypeEnum.USERAPP.getPhpType());
        Example<Users> of = Example.of(users);
        long user = usersRepository.count(of);
        //骑手
        users.setUserType(AppIdTypeEnum.QISHOU_XCX.getPhpType());
        long qishou = usersRepository.count(Example.of(users));
        //门店
        users.setUserType(AppIdTypeEnum.MENDIAN_XCX.getPhpType());
        long mendian = usersRepository.count(Example.of(users));
        //区代
        users.setUserType(AppIdTypeEnum.QUDAI_XCX.getPhpType());
        long qudai = usersRepository.count(Example.of(users));
        //市代
        users.setUserType(AppIdTypeEnum.SHIDAI_XCX.getPhpType());
        long shidai = usersRepository.count(Example.of(users));
        Map<String,Long> map = new HashMap<>();
        map.put("user",user);
        map.put("qishou",qishou);
        map.put("mendian",mendian);
        map.put("qudai",qudai);
        map.put("shidai",shidai);
        return ResHttp.okData(map);
    }
}
